<%@page import="efrei.ngo.entity.User"%>
<%@page import="efrei.ngo.util.GeneralUnil"%>
<%@page import="efrei.ngo.util.DatabaseAccess"%>
<%@page import="efrei.ngo.entity.ItemSimple"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Forum List</title>
<link rel="stylesheet" href="../css/button.css">
<link rel="stylesheet"
	href="../css/custom-theme/jquery-ui-1.8.18.custom.css">
<link rel="stylesheet" href="../css/custom-theme/jquery.ui.all.css">
<script type="text/javascript" src="../js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.8.18.custom.min.js"></script>
<script type="text/javascript" src="../js/external/jquery.bgiframe-2.1.2.js"></script>
<script type="text/javascript" src="../js/ui/jquery.ui.button.js"></script>
<script type="text/javascript" src="../js/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="../js/ui/jquery.ui.mouse.js"></script>
<script type="text/javascript" src="../js/ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../js/ui/jquery.ui.dialog.js"></script>
<script type="text/javascript" src="../js/js4forumList.js"></script>
<style type="text/css">
textarea {
	resize: none;
}

th {
	font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica,sans-serif;
	color:#FFF;
	border-right: 1px solid #C1DAD7;
	border-bottom: 1px solid #C1DAD7;
	border-top: 1px solid #C1DAD7;
	letter-spacing: 2px;
	text-transform: uppercase;
	text-align: left;
	padding: 6px 6px 6px 12px;
	background:#666 no-repeat;
}

td {
	border-right: 1px solid #C1DAD7;
	border-bottom: 1px solid #C1DAD7;
	background: #fff;
	font-size:11px;
	padding: 6px 6px 6px 12px;
	color: #4f6b72;
}

</style>
</head>
<!-- ------------------------------ -->
<%if(request.getSession().getAttribute("user")==null){
	response.sendRedirect("..");
	return;
}
%>
<!-- ------------------------------ -->
<body onLoad="inital();">
<div align="center">
	<!----------------------------------->
	<!-- this is in the bump-up dialog -->
	<div id="dialog-form" title="Publish a new POST"
		style="font-size: 12px">
		<form>
			<fieldset>
				<div align="center">
					<table width="100%">
						<tr>
							<td width="40%" align="right">Title</td>
							<td width="60%"><input type="text" style="width: 100%"
								name="titleName" id="titleName"
								class="text ui-widget-content ui-corner-all" /></td>
						</tr>
						<tr>
							<td align="right">Description</td>
							<td><input type="text" style="width: 100%"
								name="description" id="description" value=""
								class="text ui-widget-content ui-corner-all" /></td>
						</tr>
						<tr>
							<td align="right" style="vertical-align: top">Context</td>
							<td><textarea name="context" id="context"
									class="text ui-widget-content ui-corner-all"
									style="height: 200px; width: 100%"></textarea></td>
						</tr>
						<tr>
							<td align="right">Accessible To</td>
							<td><select id="authenSelect" name="authenSelect"
								style="align: left; width: 50%">
									<option>All</option>
									<option>For insiders</option>
							</select></td>
						</tr>
					</table>
				</div>
			</fieldset>
		</form>
	</div>
	<h2 align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Forum</h2>
	<div width="80%">
		<p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="button" onClick="onclick_newPost();" value="New Post" style="font-size:14px;height:35px;width:80px"></p>
        <hr>
	</div>
	<table id="tblPostList" name="tblPostList" width="90%" border="1"  cellpadding="0" cellspacing="0" border="0">
		<tr>
			<th width="8%">Seq.</th>
			<th width="10%">Name</th>
			<th>Description</th>
			<th width="10%">Date</th>
			<th width="12%">Owner</th>
			<th></th>
		</tr>
		<%
			DatabaseAccess.connectToDB();
			ArrayList<ItemSimple> postList = DatabaseAccess.dbGetPostList();
			String htmlForumList = "";
			ItemSimple tempHolder;

			if(postList!=null){
				for (int i = 1, len = postList.size(); i <= len; i++) {
					tempHolder = postList.get(i - 1);
					htmlForumList += "<tr>"
							+ "<td class=\"row\">"
							+ i
							+ "</td>"
							+ "<td class=\"row\">"
							+ tempHolder.getTitleName()
							+ "</td>"
							+ "<td class=\"row\">"
							+ tempHolder.getDescription()
							+ "</td>"
							+ "<td class=\"row\">"
							+ GeneralUnil.changeDateToString(tempHolder
									.getPostDate()) + "</td>" + "<td class=\"row\">"
							+ tempHolder.getOwner().getUsername() + "</td>"
							+ "<td class=\"row\">" + "<a href=\"Forum.jsp?postID="
							+ tempHolder.getPostID() + "\">See Details</a>"
							+ "</td>" + "</tr>";
				}
				if(postList.size()==0){
					htmlForumList+="<tr><td colspan='6' align='center'>Nothing to display</td></tr>";
				}
			}else{
				htmlForumList+="<tr><td colspan='6' align='center'>Nothing to display</td></tr>";
			}
			DatabaseAccess.endConnectionToDB();
		%>
		<%=htmlForumList%>
	</table>
	</div>
</body>
</html>